class StokPerpindahansController < ApplicationController
  # GET /stok_perpindahans
  # GET /stok_perpindahans.json
  def index
    @stok_perpindahans = StokPerpindahan.all
    
    #transfer data berhasil sebelumnya buat xml dari Sql Yog pilih KodeBrg dan Stok lalu import dr navicat
    
    #@stok_perpindahans.each do |stok|
    #  if stok.Stok > 0
    #    @barang = nil
    #    @barang = Barang.new
    #    @barang = Barang.where("KodeBrg =?", stok.KodeBrg).first
    #    @barang.stok = stok.Stok
    #    @barang.save
    #  end  
    #end

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @stok_perpindahans }
    end
  end

  # GET /stok_perpindahans/1
  # GET /stok_perpindahans/1.json
  def show
    @stok_perpindahan = StokPerpindahan.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @stok_perpindahan }
    end
  end

  # GET /stok_perpindahans/new
  # GET /stok_perpindahans/new.json
  def new
    @stok_perpindahan = StokPerpindahan.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @stok_perpindahan }
    end
  end

  # GET /stok_perpindahans/1/edit
  def edit
    @stok_perpindahan = StokPerpindahan.find(params[:id])
  end

  # POST /stok_perpindahans
  # POST /stok_perpindahans.json
  def create
    @stok_perpindahan = StokPerpindahan.new(params[:stok_perpindahan])

    respond_to do |format|
      if @stok_perpindahan.save
        format.html { redirect_to @stok_perpindahan, notice: 'Stok perpindahan was successfully created.' }
        format.json { render json: @stok_perpindahan, status: :created, location: @stok_perpindahan }
      else
        format.html { render action: "new" }
        format.json { render json: @stok_perpindahan.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /stok_perpindahans/1
  # PUT /stok_perpindahans/1.json
  def update
    @stok_perpindahan = StokPerpindahan.find(params[:id])

    respond_to do |format|
      if @stok_perpindahan.update_attributes(params[:stok_perpindahan])
        format.html { redirect_to @stok_perpindahan, notice: 'Stok perpindahan was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @stok_perpindahan.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /stok_perpindahans/1
  # DELETE /stok_perpindahans/1.json
  def destroy
    @stok_perpindahan = StokPerpindahan.find(params[:id])
    @stok_perpindahan.destroy

    respond_to do |format|
      format.html { redirect_to stok_perpindahans_url }
      format.json { head :ok }
    end
  end
end
